﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;


using MongoDB.Driver;

namespace Monitor.Core.Sensor
{
    class MongoSensor : AbstractSensor
    {
        public MongoSensor(int id, Uri uri)
            : base(id, uri)
        {
        }

        protected override ServiceStatus PingService()
        {
            MongoClient c = new MongoClient(new MongoUrl(this._uri.ToString()));
            var s = c.GetServer();
            s.Connect();
            var db = s.GetDatabase("admin");
            var result = db.RunCommand("ping");
            if (result.Ok)
            {
                return ServiceStatus.Alive;
            }
            else
            {
                this._lastError = "result not equal Ok";
                return ServiceStatus.Dead;
            }
        }
    }
}
